<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>巡检任务执行与回执</title>
    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h4 class="page-subhead-line">巡检任务管理 >> 执行与回执</h4>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        *****
                    </div>
                    <div class="panel-body">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <div class="col-sm-2">
                                    <label for="inspectionTaskCode">任务编号：</label>
                                    <input type="text" class="form-control" id="inspectionTaskCode"
                                           placeholder="请输入任务编号">
                                </div>

                                <div class="col-sm-2">
                                    <label for="lineCode">线路编号：</label>
                                    <input type="text" class="form-control" id="lineCode" placeholder="请输入任务编号">
                                </div>
                                <div class="col-sm-2">
                                    <label for="taskStatusName">任务状态：</label>
                                    <input type="text" class="form-control" id="taskStatusName" placeholder="请输入任务状态">
                                </div>
                                <div class="col-sm-2">
                                    <label for="issuedByName">下发人：</label>
                                    <input type="text" class="form-control" id="issuedByName" placeholder="请输入下发人">
                                </div>
                                <div class="col-sm-2">
                                    <label for="issuedTimestart">下发时间：</label>
                                    <input type="text" class="form-control" id="issuedTimestart" placeholder="请输入下发时间">
                                </div>
                                <div class="col-sm-2">
                                    <label for="issuedTimeend">：</label>
                                    <input type="text" class="form-control" id="issuedTimeend" placeholder="请输入下发时间">
                                </div>

                            </div>
                            <div class="form-group">
                                <div class="col-sm-1">
                                    <button class="btn btn-info col-sm-12" id="submitcx">查询</button>
                                </div>
                                <div class="col-sm-1">
                                    <button class="btn btn-info col-sm-12" id="Empty">清空</button>
                                </div>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>任务编号</th>
                                    <th>任务名称</th>
                                    <th>巡检线路</th>
                                    <th>起始杆号</th>
                                    <th>终止杆号</th>
                                    <th>下发人</th>
                                    <th>下发时间</th>
                                    <th>任务状态</th>
                                    <th>任务完成时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="userlist"></tbody>
                            </table>
                            <ul class="pagination">
                                <li>
                                    <a href="">首页</a>
                                </li>
                                <li>
                                    <a href="">&laquo;</a>
                                </li>
                                <li>
                                    <a></a>
                                </li>
                                <li>
                                    <a href="">&raquo;</a>
                                </li>
                                <li>
                                    <a href="">末页</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- End  Kitchen Sink -->
            </div>

        </div>
    </div>
</div>
<!-- /. FOOTER  -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="../assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.min.js"></script>


<script type="application/javascript">

    $(function () {
        getPage(1);
        $("#submitcx").click(function () {
            getPage(1);
        });
        $("#InspectionAdd").click(function () {
            InspectionAdds();
        });
        Empty();

    });

    //分页
    function getPage(pageNo) {
        var insTaskCode = $("#inspectionTaskCode").val().trim();
        var linCode = $("#lineCode").val().trim();
        var tasStatusName = $("#taskStatusName").val().trim();
        var issdByName = $("#issuedByName").val().trim();
        var issdTimestart = $("#issuedTimestart").val().trim();
        var issdTimeend = $("#issuedTimeend").val().trim();
        $.ajax({
            url: "http://localhost:8080/inspectask/allInspectask",
            type: "get",
            data: {
                "currentPage": pageNo,
                "inspectionTaskCode": insTaskCode,
                "lineCode": linCode,
                "taskStatusName": tasStatusName,
                "issuedByName": issdByName,
                "issuedTimestart": issdTimestart,
                "issuedTimeend": issdTimeend
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 200 && data.obj.lists != null) {
                    $("#userlist").html("");
                    var pageNum = data.obj.currPage;//当前页数
                    var totalPages = data.obj.totalPage;//总页数
                    var list = data.obj.lists;//每页的显示的数据
                    for (var i = 0; i < list.length; i++) {
                        var inspeId = list[i].id;
                        var inspectionTaskCode = list[i].inspectionTaskCode;
                        var inspectionTaskName = list[i].inspectionTaskName;
                        var lineCodes = list[i].lineCode;
                        var lineName = list[i].lineName;
                        var startPoleCode = list[i].startPoleCode;
                        var endPoleCode = list[i].endPoleCode;
                        var issuedByName = list[i].issuedByName;
                        var issuedTime = list[i].issuedTime;
                        var taskStatusName = list[i].taskStatusName;
                        var finishTime = list[i].finishTime;

                        //数据处理
                        if (finishTime == null) {
                            finishTime = '';
                        }
                        var caozuo = "";
                        if (taskStatusName == null) {
                            taskStatusName = '';
                        } else if (taskStatusName == "待分配" || taskStatusName == "已完成") {
                            caozuo = "<a class='btn btn-success' href='javascript: getDetails(" + inspeId + ",\"" + lineCodes + "\")'>查看</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success'>执行录入</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success'>执行</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success' >修改</a>"
                        } else if (taskStatusName == "已分配") {
                            caozuo = "<a class='btn btn-success' href='javascript: getDetails(" + inspeId + ",\"" + lineCodes + "\")'>查看</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success'>执行录入</a>&nbsp;&nbsp;" +
                                "<a class='btn btn-success' href='javascript:carriedOut(" + inspeId + ")'>执行</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success'>修改</a>"
                        } else if (taskStatusName == "执行中") {
                            caozuo = "<a class='btn btn-success' href='javascript: getDetails(" + inspeId + ",\"" + lineCodes + "\")'>查看</a>&nbsp;&nbsp;" +
                                "<a  class='btn btn-success'  href='javascript: ReceiptEntry(" + inspeId + ",\"" + lineCodes + "\")'>回执录入</a>&nbsp;&nbsp;" +
                                "<a disabled class='btn btn-success'>执行</a>&nbsp;&nbsp;" +
                                "<a  class='btn btn-success' href='javascript: receiptUpdate(" + inspeId + ",\"" + lineCodes + "\")'>修改</a>"
                        }

                        var tr = "<tr>" +
                            "<td>" + inspectionTaskCode + "</td>" +
                            "<td>" + inspectionTaskName + "</td>" +
                            "<td>" + lineName + "</td>" +
                            "<td>" + startPoleCode + "</td>" +
                            "<td>" + endPoleCode + "</td>" +
                            "<td>" + issuedByName + "</td>" +
                            "<td>" + issuedTime + "</td>" +
                            "<td>" + taskStatusName + "</td>" +
                            "<td>" + finishTime + "</td>" +
                            "<td>" + caozuo + "</td>" + "</tr>";

                        $("#userlist").append(tr);
                    }
                    /* 按钮换页 */
                    $(".pagination li:eq(0) a").attr("href", "javascript:getPage(1)");
                    $(".pagination li:eq(1) a").attr("href", "javascript:getPage(" + (pageNum - 1) + ")");
                    $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + (pageNum + 1) + ")");
                    $(".pagination li:eq(4) a").attr("href", "javascript:getPage(" + totalPages + ")");

                    if (pageNum <= 1) {
                        $(".pagination li:eq(1) a").attr("href", "javascript:getPage(1)");

                    } else if (pageNum >= totalPages) {
                        $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + totalPages + ")");
                    }
                    //当前页和总页数的显示

                    $(".pagination li:eq(2) a").html(pageNum + "/" + totalPages + "页");

                } else if (data.status == 500 && data.msg) {
                    alert(data.msg);
                }
            },
            error: function () {
                console.log("与后台断开连接！！！");
            }
        })
    }

    //清空条件
    function Empty() {
        $("#Empty").click(function () {
            $("#inspectionTaskCode").val("");
            $("#lineCode").val("");
            $("#taskStatusName").val("");
            $("#issuedByName").val("");
            $("#issuedTimestart").val("");
            $("#issuedTimeend").val("");
        })

    }

    //详情
    function getDetails(inspeId, lineCodes) {
        sessionStorage.setItem("inspeId", inspeId);
        sessionStorage.setItem("lineCodes", lineCodes);
        window.location.href = "Inspec_view.html";
    }

    //执行
    function carriedOut(inspeId) {
        var url = "http://localhost:8080/inspectask/carriedOut/" + inspeId;
        $.ajax({
            url: url,
            type: 'PUT',
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                if (data.obj == 1) {
                    alert(data.msg)
                    window.location.href = 'ExecutionAndReceipt.html';
                }
            }
        })
    }

    //回执录入
    function ReceiptEntry(inspeId, lineCodes) {
        sessionStorage.setItem("inspeId", inspeId);
        sessionStorage.setItem("lineCodes", lineCodes);
        window.location.href = 'Inspec_receiptEntry.html';
    }

    //修改
    function receiptUpdate(inspeId,lineCodes) {
        sessionStorage.setItem("inspeId", inspeId);
        sessionStorage.setItem("lineCodes", lineCodes);
        window.location.href = "Inspec_receiptUpdate.html";
    }


</script>

</body>
</html>
